<div class="sectionY">
    <a href="javascript:history.back()">
        <img src="__PUBLIC__/home/images/a4.png" class="a1" alt="">
    </a>
    <p class="p1">商品详情</p>
</div>
<div class="kong1"></div>
<div class="gx_shop1 gx_shop1x">
    <div class="ppp">
        <div class="swiper-container" id="mm">
            <div class="swiper-wrapper">
                {foreach $goods['group_images'] as $item}
                <div class="swiper-slide"><img src="{$item}" alt=""></div>
                {/foreach}
            </div>
            <div class="swiper-pagination"></div>
        </div>
    </div>
</div>
<div class="gx_shop4">
    <div class="e_section3">
        <div class="container">
            <div class="a1">
                <p class="p2">
                    <span class="s1">{$goods.price}</span>
                    <s>{$goods.original_price}</s>
                </p>
                <p class="p1 ">{$goods.title}</p>
                <p id="choose_show" class="p3 clearfix choose_spec">
                    <span class="s1">请选择</span>
                    <img src="__PUBLIC__/home/images/a39.png" alt="">
                    <span class="s2 chao">{$goods.choose_title}</span>
                </p>
            </div>
        </div>
    </div>
</div>
<div class="ge"></div>
<div class="gx_shop5">
    <div class="title">
        <p class="p1">详情</p>
    </div>
    <div class="center">
        <!-- 详情 -->
        {$goods.detail}
    </div>
</div>
<div class="kong"></div>
<div class="gx_shop6">
    {if $goods['spec']['def']['stock']>0&&$goods['status']==1}
    <a href="javascript:void(0);" class="choose_spec">立即购买</a>
    {else/}
    <a href="javascript:;" style="background: #aaa;">{if $goods['status']!=1}商品已下架{else/}商品已售罄{/if}</a>
    {/if}
</div>
<!-- 规格 -->
<div class="guige">
    <div class="guige_1">
        <img src="__PUBLIC__/home/images/close.png" alt="" class="im1 close_btn">
        <div class="title clearfix">
            <div class="logo">
                <img src="{$goods.spec.def.img_url}" alt="">
            </div>
            <div class="center">
                <p class="p1 chao">{$goods.spec.def.title}</p>
                <p class="p2">{$goods.spec.def.price}</p>
            </div>
        </div>
        <div class="list list_all">
            <ul class="clearfix">
                {foreach $goods['spec']['list'] as $va}
                <li>
                    <span class="s1 select" data-id="{$va._id}" data-title="{$va.title}" data-price="{$va.price}" data-img="{$va.img_url}">{$va.title}</span>
                </li>
                {/foreach}
            </ul>
        </div>
        <div class="last clearfix">
            <p class="p1">数量</p>
            <p class="p2">
                <img src="__PUBLIC__/home/images/min.png" alt="" class="del_btn">
                <span class="s1">1</span>
                <img src="__PUBLIC__/home/images/add.png" alt="" class="add_btn">
            </p>
        </div>
        <div class="next">
            <a href="javascript:void(0);" id="buyNow">立即购买</a>
        </div>
    </div>
</div>
<script>
    $(function () {

        var swiper = new Swiper('#mm', {
            spaceBetween: 30,
            centeredSlides: true,
            autoplay: {
                delay: 2000,
                disableOnInteraction: false,
            },
            pagination: {
                el: '.swiper-pagination',
                clickable: true,
            },
        });

        /**********商品信息************/
        window.goods_id = "{$goods._id}";
        window.is_collection = "{$goods['is_collection']}";
        window.spec_id = 0;
        window.spec_title = '';
        window.num = 1;
        /**********商品信息************/

        //唤起规格
        $(".choose_spec").click(function () {
            $(".guige").show();
            showChoose();
        });
        //关闭规格
        $(".close_btn").click(function(){
            $(".guige").hide()
        });
        //选择规格
        $("#all_spec li").click(function(){
            $("#all_spec li").removeClass('select');
            $(this).addClass('select');
            spec_id = $(this).attr('data-id');
            $(".choose_alr .logo img").attr('src',$(this).attr('data-img'));
            $(".choose_alr .p1").html($(this).attr('data-title'));
            $(".choose_alr .p2").html('￥'+$(this).attr('data-price'));
            spec_title=$(this).attr('data-title');
            showChoose();
        });

        //减量
        $(".del_btn").click(function(){
            num--;
            if(num<=1){
                num = 1;
            }
            $(this).siblings(".s1").text(num);
            showChoose();
        });
        //加量
        $(".add_btn").click(function(){
            num++;
            $(this).siblings(".s1").text(num);
            showChoose();
        });
        //显示选择
        function showChoose() {
            $("#choose_show .s1").html('已选择');
            $("#choose_show .s2").html(spec_title+' * '+num);
        }
        $("#buyNow").click(function () {
            var data = [];
            var one = {};
            one.goods_id=goods_id;
            one.spec_id=spec_id;
            one.num=num;
            data.push(one);
            modal.ajax("{:url('Order/beforeCheck')}",{data:data,type:2},function (res) {
                if(res.result_code==0){
                    window.location.href=res.result_data.url;
                }else{
                    modal.msg(res.result_info);
                }
            });
        });

    })
</script>